//
//  paySelectViewController.m
//  CenturyInterconnection
//
//  Created by l-sheng on 6/23/16.
//  Copyright © 2016 Shanghai DuRui Information Technology Company. All rights reserved.
//

#import "paySelectViewController.h"

@interface paySelectViewController () <UITableViewDelegate,UITableViewDataSource>

@property(nonatomic,strong) UITableView *myTableView;

@property(nonatomic,strong) NSArray * allData;

@end


@implementation paySelectViewController


-(UITableView *)myTableView{
    if (!_myTableView) {
        _myTableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
        _myTableView.frame = CGRectMake(0, 0, KScreenWidth, KScreenHeight);
        _myTableView.delegate = self;
        _myTableView.dataSource = self;
        [self.view addSubview:_myTableView];
    }
    return _myTableView;
}






- (void)viewDidLoad{
    
    self.allData = [[NSArray alloc] init];
    
    [self getPayMethodData];
    
    
    [self.myTableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
}


- (void)getPayMethodData{
    
    // http://viprunningonline.com/api/index.php?main_page=payment_method
    
    NSString*urlStr=[NSString stringWithFormat:@"%@",HTTP_ADDRESS];
    
    NSDictionary*params=@{@"main_page":@"payment_method",
                          @"zenid":[UserSession instance].cookie};
    
    HttpManager*manager=[[HttpManager alloc]init];
    
    
    [manager getDataFromNetworkWithUrl:urlStr parameters:params compliation:^(id data, NSError *error) {
        
        NSString * number=[NSString stringWithFormat:@"%@",data[@"status"]];
        
        if ([number isEqualToString:@"1"]) {
            
            //NSLog(@"%@",data);
            
            self.allData = data[@"data"];
            
            [self.myTableView reloadData];
            
            
        }else{
            [JRToast showWithText:data[@"status_message"] duration:2.0];
        }
        
    }];
}

#pragma mark - tabledegete
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 44;
}

#pragma mark - datasource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return  self.allData.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell * cell=[tableView dequeueReusableCellWithIdentifier:@"cell" ];
    if (!cell) {
        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell"];
        cell.selectionStyle=UITableViewCellSelectionStyleNone;
    }
    
    
    //NSLog(@"%@",self.allData[indexPath.row]);
    
    cell.textLabel.text = [self.allData[indexPath.row] objectForKey:@"title"];
    
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if([self.delegate respondsToSelector:@selector(paySelectDelegeMethod:)])
    {
        [self.delegate paySelectDelegeMethod:self.allData[indexPath.row]];
    }
    [[SlideNavigationController sharedInstance] popViewControllerAnimated:YES];
}


@end
